﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using DotNetNuke.Tests.UI.WatiN.SiteTests;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;

namespace DotNetNuke.Tests.UI.WatiN.SiteTests
{
    [TestFixture]
    public class AdminMenuTests : STBase
    {


        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {
            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {

            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        public void Admin_Console_Page_Loads_Correctly()
        {
           //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Console Page
                ieInstance.GoTo(SiteURL + "/Admin.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnAdminPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Admin Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Basic Features"), "AdminTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnConsolePage.jpg");
                String[] linkTitles = new String[]
                                            {
                                                "Site Settings", "Pages", "Extensions", "Languages", "Skins",
                                                "Security Roles", "User Accounts", "Vendors", "Site Log", "Newsletters",
                                                "File Manager", "Recycle Bin", "Event Viewer", "Site Wizard",
                                                "Google Analytics", "Taxonomy", "Search Engine Site Map"
                                            };
                foreach (string link in linkTitles)
                {
                    watinAssert.AssertIsTrue(ieInstance.Div(Find.ByTitle(s => s.Contains(link))).Exists, "MissingLinkOnAdminPage.jpg", "Looking for "+ link);
                }

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminConsoleExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Admin_Site_Settings_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Site Settings Page
                ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnSiteSettingsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Site Settings Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Site Settings"), "SiteSettingsTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnSiteSettingsPage.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminSiteSettingsExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Admin_Pages_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);
                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Page Page
                ieInstance.GoTo(SiteURL + "/Admin/Pages.aspx");
                System.Threading.Thread.Sleep(2500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnPagesPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Admin Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Pages"), "PagesTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnPagesPage.jpg");
                AdminPagesPage pagesPage = new AdminPagesPage(homePage);
                watinAssert.AssertIsTrue(pagesPage.PagesPanel.Exists, "PagePanelMissing.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminPagesExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Admin_Extensions_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Extensions Page
                ieInstance.GoTo(SiteURL + "/Admin/Extensions.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnExtensionsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Extensions Page, view the screen shot and exception text log for more information on the error. ");
                }
                System.Threading.Thread.Sleep(1500);
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Extensions"), "ExtensionsTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnExtensionsPage.jpg");
                ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
                watinAssert.AssertIsTrue(extensionsPage.InstalledExtensionDiv.Exists, "MissingInstalledExtensionsDiv.jpg");
                watinAssert.AssertIsTrue(extensionsPage.AvailableExtensionDiv.Exists, "MissinAvailableExtensionsDiv.jpg");
                watinAssert.AssertIsTrue(extensionsPage.MoreExtensionDiv.Exists, "MissingMoreExtensionsDiv.jpg");
                watinAssert.AssertIsFalse(extensionsPage.InstallExtensionsWizardLink.Exists, "InstallExtensionLinkPresent.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminExtensionsExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Admin_Languages_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(2500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Languages Page
                ieInstance.GoTo(SiteURL + "/Admin/Languages.aspx");
                System.Threading.Thread.Sleep(2500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnLanguagesPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Languages Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Language Management"), "LanguagesTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnLanguagesPage.jpg");
                LanguagePage languagePage = new LanguagePage(homePage);
                watinAssert.AssertIsTrue(languagePage.LanguageTable.Exists, "MissingLanguageTable.jpg");


                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminLanguagesExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Admin_Skins_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Skins Page
                ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnSkinsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Skins Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Skin Editor"), "SkinTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 2, "TooManyTitleSpansOnSkinPage.jpg");
                AdminSkinPage skinPage = new AdminSkinPage(homePage);
                watinAssert.AssertIsTrue(skinPage.ContainersTable.Exists, "MissingContainersTable.jpg");
                watinAssert.AssertIsTrue(skinPage.SkinsTable.Exists, "MissingSkinsTable.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminSkinExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
            
        }

        [Test]
        public void Admin_Security_Roles_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Security Roles Page
                ieInstance.GoTo(SiteURL + "/Admin/SecurityRoles.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnSecurityRolesPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Security Roles Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Security Roles"), "SecurityRolesTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnSecurityRolesPage.jpg");
                SecurityRolesPage rolesPage = new SecurityRolesPage(homePage);
                watinAssert.AssertIsTrue(rolesPage.RolesTable.Exists, "MissingRolesTable.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminSecurityRolesExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
        }

        [Test]
        public void Admin_User_Accounts_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin User Accounts Page
                ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnUserAccountsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the User Accounts Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("User Accounts"), "UserAccountsTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnUserAccountsPage.jpg");
                UserPage userPage = new UserPage(homePage);
                watinAssert.AssertIsTrue(userPage.UserTable.Exists, "MissingUserTable.jpg");


                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminUserAccountsExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
            
        }

        [Test]
        public void Admin_Vendors_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Vendors Page
                ieInstance.GoTo(SiteURL + "/Admin/Vendors.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnVendorsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Vendors Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Vendors"), "VendorsTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnVendorsPage.jpg");
                VendorsPage vendorsPage = new VendorsPage(homePage);
                watinAssert.AssertIsTrue(vendorsPage.VendorTable.Exists, "MissingVendorTable.jpg");


                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminVendorsExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }
            
        }

        [Test]
        public void Admin_Site_Log_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Site Log Page
                ieInstance.GoTo(SiteURL + "/Admin/SiteLog.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnSiteLogPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Site Log Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Site Log"), "SiteLogTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnSiteLogPage.jpg");
                AdminSiteLogPage siteLogPage = new AdminSiteLogPage(homePage);
                watinAssert.AssertIsTrue(siteLogPage.ReportTypeSelectList.Exists, "MissingReportTypeSelectList.jpg");


                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminSiteLogExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }

        }

        [Test]
        public void Admin_Newsletters_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Newsletter Page
                ieInstance.GoTo(SiteURL + "/Admin/Newsletters.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnNewslettersPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Newsletters Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Newsletters"), "NewsletterTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnNewslettersPage.jpg");
                NewsletterPage newsletterPage = new NewsletterPage(homePage);
                watinAssert.AssertIsTrue(newsletterPage.AdditionalEmailsField.Exists, "MissingAdditionalEmailsField.jpg");
                watinAssert.AssertIsTrue(newsletterPage.SubjectField.Exists, "MissingSubjectField.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminNewsletterExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }

        }

        [Test]
        public void Admin_File_Manager_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin File Manager Page
                ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
                System.Threading.Thread.Sleep(2500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnFileManagerPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the File Manager Page, view the screen shot and exception text log for more information on the error. ");
                }
                System.Threading.Thread.Sleep(2500);
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("File Manager"), "FileManagerTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnFileManagerPage.jpg");
                FileManagerPage fileManagerPage = new FileManagerPage(homePage);
                watinAssert.AssertIsTrue(fileManagerPage.FileManagerTable.Exists, "MissingFileManagerTable.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminFileManagerExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }

        }

        [Test]
        public void Admin_Recycle_Bin_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Recycle Bin Page
                ieInstance.GoTo(SiteURL + "/Admin/RecycleBin.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnRecycleBinPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Recycle Bin Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Recycle Bin"), "RecycleBinTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnRecycleBinPage.jpg");
                RecycleBinPage recycleBin = new RecycleBinPage(homePage);
                watinAssert.AssertIsTrue(recycleBin.ModulesRecycleBin.Exists, "ModuleRecycleBinMissing.jpg");
                watinAssert.AssertIsTrue(recycleBin.PagesRecycleBin.Exists, "PageRecycleBinMissing.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminRecycleBinExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }

        }

        [Test]
        public void Admin_Event_Viewer_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Event Viewer Page
                ieInstance.GoTo(SiteURL + "/Admin/LogViewer.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnEventViewerPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Event Viewer Page, view the screen shot and exception text log for more information on the error. ");
                }
                System.Threading.Thread.Sleep(1500);
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Log Viewer"), "LogViewerTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnEventViewerPage.jpg");
                EventViewerPage eventViewer = new EventViewerPage(homePage);
                watinAssert.AssertIsTrue(eventViewer.LogHeaderDiv.Exists, "MissingEventTable.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminLogViewerExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }

        }

        [Test]
        public void Admin_Site_Wizard_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Site Wizard Page
                ieInstance.GoTo(SiteURL + "/Admin/SiteWizard.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnSiteWizardPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Site Wizard Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Site Wizard"), "SiteWizardTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnSiteWizardPage.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminSiteWizardExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }

        }

        [Test]
        public void Admin_Google_Analytics_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Site Wizard Page
                ieInstance.GoTo(SiteURL + "/Admin/GoogleAnalytics.aspx");
                System.Threading.Thread.Sleep(2500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnGoogleAnalyticsPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Google Analytics Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Google Analytics"), "GoogleAnalyticsTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnGoogleAnalyticsPage.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminGoogleAnalyticsExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }

        }

        [Test]
        public void Admin_Taxonomy_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminPagesLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Taxonomy Page
                ieInstance.GoTo(SiteURL + "/Admin/Taxonomy.aspx");
                System.Threading.Thread.Sleep(1500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "ErrorOnTaxonomyPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Taxonomy Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Taxonomy Manager"), "TaxonomyTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnTaxonomyPage.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminTaxonomyExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }

        }

        [Test]
        public void Admin_Search_Engine_SiteMap_Page_Loads_Correctly()
        {
            //Arrange
            string capturePath = CapturePath + @"\AdminMenuTests\AdminSearchEngineSiteMapLoadCorrectly\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            int errorCount = 0;
            try
            {
                loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
                System.Threading.Thread.Sleep(1500);

                //Act & Assert
                //Visit the pages in the admin menu to assert that no errors occurred
                //Admin Search Engine Site Map Page
                ieInstance.GoTo(SiteURL + "/Admin/SearchEngineSiteMap.aspx");
                System.Threading.Thread.Sleep(2500);
                if (homePage.PageContainsErrors())
                {
                    errorCount++;
                    //Take a screen Capture
                    ieInstance.CaptureWebPageToFile(CapturePath + "SearchEngineSiteMapPage.jpg");
                    TestLog.WriteHighlighted("WARNING:");
                    TestLog.WriteLine("An error occurred on the Search Engine SiteMap Page, view the screen shot and exception text log for more information on the error. ");
                }
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Search Engine SiteMap"), "SearchEngineSiteMapTitleSpanMissing.jpg");
                watinAssert.AssertIsTrue(homePage.ModuleTitleSpans.Count == 1, "TooManyTitleSpansOnSearchEngineSiteMapPage.jpg");

                if (errorCount > 0)
                {
                    //Record any recent exceptions in the log
                    loginPage.LogoffUser();
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                    ieInstance.GoTo(SiteURL + "/Host/SQL.aspx");
                    HostSQLPage SQLPage = new HostSQLPage(homePage);
                    SQLPage.CheckForRecentExceptionsWriteToFile(CapturePath + "AdminSearchEngineSiteMapExceptions.txt", SiteType.Equals("Qualifier"));
                }
            }
            catch (Exception e)
            {
                if (!e.ToString().Contains("AssertionFailureException"))
                {
                    ieInstance.CaptureWebPageToFile(capturePath + "Exception.jpg");
                    Assert.IsTrue(false, "An Exception Occured during the test, view the screen shot for more information. " + System.Environment.NewLine + e.ToString());
                }
                else
                {
                    throw e;
                }
            }

        }
        
        #endregion
    }
}

